package initialize

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commEnv"
	"gitee.com/fierce_wolf/go-fox-edge-common/commLogger"
	"gitee.com/fierce_wolf/go-fox-edge-iot-common/iotAPI"
	"gitee.com/fierce_wolf/go-fox-edge-iot-common/iotCommInitialize"
	"go-fox-edge-iot-fox-publish/component"
	"go-fox-edge-iot-fox-publish/entityManager"
	"go-fox-edge-iot-fox-publish/publish"
	"go-fox-edge-iot-fox-publish/remote"
)

func Initialize() {
	// 设置环境变量
	commEnv.Service.ServiceType = "service"
	commEnv.Service.ServiceName = "iot-fox-publish-native"
	commEnv.Service.ModelType = "iot-cloud"
	commEnv.Service.ModelName = "iot-fox-publish"
	commEnv.Service.ApplicationName = "iot-fox-publish-native"
	commEnv.SetWorkPath(2)

	commLogger.Info("------------- iot-fox-publish-native 初始化开始！-------------")

	// 绑定API接口
	iotAPI.EntityManager.Instance = entityManager.EntityManager
	iotAPI.LocalConfig.Initialize = component.LocalConfig
	iotAPI.MqttHandler.MqttHandler = remote.MqttHandler

	// 初始化公共模块
	iotCommInitialize.Initialize()

	// 启动推送线程
	publish.Scheduler()

	commLogger.Info("------------- iot-fox-publish-native 初始化结束！-------------")

	commLogger.Info("------------- iot-fox-publish-native 驻留在后台！-------------")
	select {}
}
